package cst.neu.yuejian_31.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.bean.SmessageBean;
import cst.neu.yuejian_31.Common.Constant;

/**
 * Created by xxe on 2017/10/31.
 */

public class SmessageAdapter extends RecyclerView.Adapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<SmessageBean> list;

    public SmessageAdapter(Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public void setList(List<SmessageBean> list){
        this.list=list;
        notifyDataSetChanged();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView messageName,messageDetail,messageTime;
        private ImageView messagePic;
        public ViewHolder(View itemView) {
            super(itemView);
            messageName= (TextView) itemView.findViewById(R.id.textView_admin_name);
            messageDetail= (TextView) itemView.findViewById(R.id.textView_message);
            messageTime= (TextView) itemView.findViewById(R.id.textView_message_time);
            messagePic= (ImageView) itemView.findViewById(R.id.imageView_admin_pic);
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=layoutInflater.inflate(R.layout.item_message,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final SmessageBean smessageBean=list.get(position);
        if(smessageBean==null)
            return;
        ViewHolder viewHolder= (ViewHolder) holder;
        viewHolder.messageName.setText(smessageBean.getAdmin_name());
        viewHolder.messageDetail.setText(smessageBean.getMessage_intro());
        viewHolder.messageTime.setText(smessageBean.getMessage_time());
        Picasso.with(context).load(Constant.ADMIN_URL+smessageBean.getAdmin_pic().toString()).into(viewHolder.messagePic);

    }

    @Override
    public int getItemCount() {
        if(list==null)return 0;
        else
            return list.size();
    }
}
